package com.gage.commons.utils;
import java.awt.image.BufferedImage;

import javax.imageio.ImageIO;

import org.springframework.web.multipart.MultipartFile;
public class ImageTools {
	   /** 
     * 获取图片宽度 
     * @param file  图片文件 
     * @return 宽度 
     */  
    public static int getImgWidth(MultipartFile file) {  
        int ret = -1;  
        try {  
        	BufferedImage image = ImageIO.read(file.getInputStream());
            ret = image.getWidth(); // 得到源图宽  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
        return ret;  
    }  
        
        
    /** 
     * 获取图片高度 
     * @param file  图片文件 
     * @return 高度 
     */  
    public static int getImgHeight(MultipartFile file) {  
        int ret = -1;  
        try {  
        	BufferedImage image = ImageIO.read(file.getInputStream());
            ret = image.getHeight(); // 得到源图高  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
        return ret;  
    } 
}
